define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            Fast.config.openArea = ['95%','95%'];
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'finance/transfer/index' + location.search,

                    table: 'course_transfer_school',
                }
            });

            var table = $("#table");
//当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                console.log(data);
                //这里我们手动设置底部的值
                $("#total").text(data.extend.total);
                $("#apply_count").text(data.extend.apply_count);
                $("#refuse_count").text(data.extend.refuse_count);
                $("#success_count").text(data.extend.success_count);
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'student_id', title: __('Student_id')},
                        // {field: 'order_id', title: __('Order_id')},
                        {field: 'type', title: __('Type'), searchList:Config.typeList,  formatter: Table.api.formatter.label},
                        {field: 'status', title: __('Status'), searchList:Config.statusList,  formatter: Table.api.formatter.label},
                        {field: 'student.name', title: __('Student.name'), operate: 'LIKE'},

                        {field: 'reason', title: __('Reason'), operate: false},
                        {field: 'refuse_content', title: __('RefuseContent'), operate: false},
                        {field: 'old_class_hour', title: __('申请订单信息'), operate: false, formatter: Controller.api.formatter.old_info},
                        {field: 'new_class_hour', title: __('转单信息'), operate: false, formatter: Controller.api.formatter.new_info},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {//渲染的方法

                old_info: function (value, row, index) {
                    var html = "-";
                    if(row.status == 2 ){
                        html =  "老订单校区："+row.school_name +"<br/>" +
                            "老订单课程：" + row.course_name+"<br/>" +
                            "老订单课时：" + row.old_class_hour+"<br/>" +
                            "老订单剩余课时：" + row.old_surplus_class_hour+"<br/>" +
                            "老订单剩余价值：" + row.old_surplus_price+"<br/>";
                    }

                    return html;
                },
                new_info: function (value, row, index) {
                    var html = "-";
                    if(row.status == 2 ){
                        html =  "新订单校区："+row.new_school_name +"<br/>" +
                            "新订单课程：" + row.new_course_name+"<br/>" +
                            "新订单课时：" + row.new_class_hour+"<br/>" +
                            "新订单剩余课时：" + row.new_surplus_class_hour+"<br/>" +
                            "新订单剩余价值：" + row.new_surplus_price+"<br/>";
                    }

                    return html;
                },

            },
        }
    };
    return Controller;
});
